<template>
	<div v-loading="loading">
		<DetailPage v-bind="formConfig" :model="formModel"></DetailPage>
		<!--  改造实施信息 -->
		<h3>改造实施信息</h3>
		<aplid-base-crud :key="theKey" ref="crud" class="w-100" v-bind="baseConfig" :paramsObj="{mainId: props.nowRowData.mainId||props.nowRowData.id}"> </aplid-base-crud>
		<div class="total_money">
			<el-text type="primary">设备安装总费用：{{ totalMoney }} 元</el-text>
		</div>
	</div>
</template>

<script setup lang="ts">
import { ref, reactive, toRefs, onMounted } from 'vue'
import DetailPage from '@/views/aplid/DetailPage/index.vue'
import { baseConfig } from './config'
import { formConfig } from '../config'
import apiMod from '@/apiMod/index'

let emits = defineEmits(['refresh'])
let props = defineProps({
	nowRowData: {
		type: Object,
		default: () => ({}),
	},
	type: {
		type: String,
		default: 'add',
	},
})
let loading = ref(false)
let totalMoney = ref(0)
let baseForm = ref()
let theKey = ref(0)
const toCancel = () => {
	emits('refresh')
}
const finalSubmit = () => {
	baseForm.value.onSubmit()
}
let formModel = ref({})
// 获取详情
const getInfo = async() =>{
	try{
		if(props.nowRowData.mainId){
			// 详情中
			formModel.value = props.nowRowData
		}else{
			// 归档中
			let res = await apiMod.view_bscAdaptOldAcceptance_page({ mainId: props.nowRowData.id })
			formModel.value = res.data.records[0]
			return Promise.resolve('ok')
		}
	}catch{
		return Promise.reject('err')
	}
	
}
// 计算金额总量
const getTotalMoney = async() => {
	try{
		let res =await apiMod.view_bscAdaptDevice_amount({ idCard: props.nowRowData.idCard, mainId: props.nowRowData.mainId||props.nowRowData.id })
		totalMoney.value = res.data
		return Promise.resolve('ok')
	}catch{
		return Promise.reject('err')
	}
}
const allReq = async() =>{
	loading.value = true
	try{
		await getInfo()
		await getTotalMoney()
		loading.value = false
	}catch{
		loading.value = false
	}
}
onMounted(() => {
	allReq()
})
</script>
<style scoped lang="scss">
.btn_part {
	margin: 0 auto;
	width: 20%;
	display: flex;
	flex-direction: row;
	justify-content: space-around;
	align-items: center;
}
.total_money {
	margin-top: 20px;
	width: 100%;
	display: flex;
	flex-direction: row-reverse;
	align-self: center;
}
</style>
